﻿Type.registerNamespace('AjaxControlToolkit');

AjaxControlToolkit.DisabledButtonBehavior = function(element) {

AjaxControlToolkit.DisabledButtonBehavior.initializeBase(this, [element]);

	this._targetButtonIDValue = null;
	this._targetLabelIDValue = null;
	this._targetDivIDValue = null;
	this._disabledTextValue = null;
	this.x = false;

}

AjaxControlToolkit.DisabledButtonBehavior.prototype = {

	initialize: function() {
		AjaxControlToolkit.DisabledButtonBehavior.callBaseMethod(this, 'initialize');

		// Initalization code
		$addHandler(this.get_element(), 'keyup',
        Function.createDelegate(this, this._onkeyup));
		this._onkeyup();

		var f = $get(this._targetLabelIDValue);
		$addHandler(f, 'click',
        Function.createDelegate(this, this._onClick));

		var e = $get(this._targetDivIDValue);
		$addHandler(e, 'mouseover',
        Function.createDelegate(this, this._onMouseOver));
        
        var g = $get(this._targetDivIDValue);
		$addHandler(e, 'mouseout',
        Function.createDelegate(this, this._onMouseOut));
	},

	dispose: function() {
		// Cleanup code
		AjaxControlToolkit.DisabledButtonBehavior.callBaseMethod(this, 'dispose');

	},

	// Property accessors 
	//
	get_TargetButtonID: function() {
		return this._targetButtonIDValue;
	},

	set_TargetButtonID: function(value) {
		this._targetButtonIDValue = value;
	},

	get_TargetLabelID: function() {
		return this._targetLabelIDValue;
	},

	set_TargetLabelID: function(value) {
		this._targetLabelIDValue = value;
	},

	get_DisabledText: function() {
		return this._disabledTextValue;
	},

	set_DisabledText: function(value) {
		this._disabledTextValue = value;
	},

	get_TargetDivID: function() {
		return this._targetDivIDValue;
	},

	set_TargetDivID: function(value) {
		this._targetDivIDValue = value;
	},

	_onkeyup: function() {

		var e = $get(this._targetButtonIDValue);
		var f = $get(this._targetLabelIDValue);
		if (e) {
			var disabled = ("" == this.get_element().value);
			e.disabled = disabled;
			if (this._disabledTextValue) {
				if (disabled) {
					this._oldValue = e.value;
					e.value = this._disabledTextValue;
					f.innerHTML = "WOW";
				}
				else {
					if (this._oldValue) {
						e.value = this._oldValue;
						f.innerHTML = "YOW";
					}
				}
			}
		}
	},

	_onClick: function() {
		var f = $get(this._targetDivIDValue);
		if (this.x == false)
		{
			f.style.backgroundColor = "yellow";
			this.x = true;
		}
		else
		{
			f.style.backgroundColor = "red";
			this.x = false;
		}
	},
	
	_onMouseOver: function() {
		var e = $get(this._targetDivIDValue);
		e.style.backgroundColor = "blue";
	},
	
	_onMouseOut: function() {
		var e = $get(this._targetDivIDValue);
		e.style.backgroundColor = "yellow";
	}

}

AjaxControlToolkit.DisabledButtonBehavior.registerClass('AjaxControlToolkit.DisabledButtonBehavior', AjaxControlToolkit.BehaviorBase);

